<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" href="https://static.nowcoder.com/images/logo_87_87.png"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
          crossorigin="anonymous">
    <link rel="stylesheet" th:href="@{/css/global.css}"/>
    <link rel="stylesheet" th:href="@{/css/login.css}"/>
    <title>忘记密码</title>
</head>
<body>
<div class="nk-container">
    <!-- 头部 -->
    <header class="bg-dark sticky-top" th:replace="index::header">
    </header>

    <!-- 内容 -->
    <div class="main">
        <div class="container pl-5 pr-5 pt-3 pb-3 mt-3 mb-3">
            <form class="mt-5" method="post" th:action="@{/forget}">
                <div id="refresh" th:fragment="refresh">
                    <div th:if="${errMsg!=null}" class="alert alert-danger alert-dismissible fade show">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <div th:text="${errMsg}" style="color: red;text-align: center">
                        </div>
                    </div>
                    <div th:if="${success!=null}" id="success" class="alert alert-success alert-dismissible fade show">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <div th:text="${success}" style="color: green;text-align: center">
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <label for="your-email" class="col-sm-2 col-form-label text-right">邮箱:</label>
                    <div class="col-sm-10">
                        <input type="email" class="form-control" th:value="${param.email}" name="email" id="your-email"
                               placeholder="请输入您的邮箱!" required>
                        <div class="invalid-feedback" id="email-hint">
                        </div>
                    </div>
                </div>
                <div class="form-group row mt-4">
                    <label for="verifycode" class="col-sm-2 col-form-label text-right">验证码:</label>
                    <div class="col-sm-6">
                        <input type="text" name="authCode" th:value="${param.authCode}"
                               th:class="|form-control ${authCodeMsg==null?'':'is-invalid'}|"
                               id="verifycode" placeholder="请输入验证码!" required>
                        <div class="invalid-feedback" th:text="${authCodeMsg}">
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <a onclick="getAuthCode()" id="getAuthCode"
                           class="btn btn-info text-white form-control">获取验证码</a>
                    </div>
                </div>
                <div class="form-group row mt-4">
                    <label for="password" class="col-sm-2 col-form-label text-right">新密码:</label>
                    <div class="col-sm-10">
                        <input type="password" th:value="${param.password}"
                               th:class="|form-control ${passwordMsg==null?'':'is-invalid'}|" name="password"
                               id="password" placeholder="请输入新的密码!" required>
                        <div class="invalid-feedback" th:text="${passwordMsg}">
                        </div>
                    </div>
                </div>
                <div class="form-group row mt-4">
                    <label for="confirm-password" class="col-sm-2 col-form-label text-right">确认密码:</label>
                    <div class="col-sm-10">
                        <input type="password" class="form-control" id="confirm-password" placeholder="请输入新的密码!"
                               required>
                        <div class="invalid-feedback" id="hint">
                        </div>
                    </div>
                </div>
                <div class="form-group row mt-4">
                    <div class="col-sm-2"></div>
                    <div class="col-sm-10 text-center">
                        <button type="submit" class="btn btn-info text-white form-control">重置密码</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- 尾部 -->
    <footer class="bg-dark" th:replace="index::footer">
    </footer>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" crossorigin="anonymous"></script>
<script th:src="@{/js/global.js}"></script>
<script th:src="@{/js/register.js}"></script>
<script th:inline="javascript">
    var time = 60;

    function getAuthCode() {
        if ($('#your-email').val().trim().length <= 0) {
            $('#your-email').addClass("is-invalid");
            var content = "邮箱不能为空";
            $("#email-hint").text(content);
            return false;
        }
        var email = $("#your-email").val();
        $('#refresh').load("/community/sendAuthCode?email=" + email);
        var obj = $("#getAuthCode");
        setTimeout(function () {
            let text = $('#success').text();
            if (text){
                countdown(obj)//实现验证码倒计时
            }
        },1000)
    }

    function countdown(obj) { //发送验证码倒计时
        if (time <= 0) {
            obj.removeClass('disabled');
            obj.text("获取验证码");
            time = 60;
            return;
        } else {
            obj.addClass('disabled');
            obj.text("重新发送(" + time + ")");
            time--;
        }
        setTimeout(function () {
            countdown(obj)
        }, 1000)
    }

</script>
</body>
</html>
